<?php

  define('BASE_ROOT_PATH', dirname(dirname(__FILE__)));
	include_once( BASE_ROOT_PATH . "/word/db/DBMySQL.php");  

	$email = $_REQUEST['email'];	
	if(empty($email)) {
	  $msg = json_encode("邮箱地址不能为空");
		echo '{"code":"1","msg":'.$msg.'}';
		exit();
	}
	$email = str_replace('\'', '\'\'', $email);
	
	$password = $_REQUEST['password'];
	if(empty($password)) {
	  $msg = json_encode("密码不能为空");
		echo '{"code":"1","msg":'.$msg.'}';
		exit();
	}	
	$password = str_replace('\'', '\'\'', $password);
	
	$nick = $_REQUEST['nick'];
	if(empty($nick)) {
	  $msg = json_encode("昵称不能为空");
		echo '{"code":"1","msg":'.$msg.'}';
		exit();
	}
	$nick = str_replace('\'', '\'\'', $nick);
	
	$isteacher = $_REQUEST['isteacher'];
	if(empty($isteacher)) {
		$isteacher = '0';
	}
	$isteacher = str_replace('\'', '\'\'', $isteacher);

	// 注册用户
	$db = new DBMySQL();
	$rs = $db->Query("select member_id from t_member where email = '$email' limit 1");
	if(!empty($rs)) { // 该邮箱地址的用户已经存在
	  $msg = json_encode("该邮箱地址的用户已经存在");
	  echo '{"code":"1","msg":'.$msg.'}';
		exit();	  
	}
	$memberId = $db->Insert("insert into t_member(email,nick,password,isteacher,create_time) values('$email','$nick','$password','$isteacher',now())");
	if(!empty($memberId)) { // 添加成功
	  // 添加会员信息表记录
	  $db->Insert("insert into t_member_info(member_id) values($memberId)");
	  $db->Insert("insert into t_news_count(member_id) values($memberId)");
	  echo '{"code":"0","msg":"'.$memberId.'"}';
	}
	
?>